﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionsLib.Dictionary
{

    public static class DictionaryExtensionsAdd
    {


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TOuterKey"></typeparam>
        /// <typeparam name="TDictionary"></typeparam>
        /// <typeparam name="TInnerKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="data"></param>
        /// <param name="outerKey"></param>
        /// <param name="innerKey"></param>
        /// <param name="value"></param>
        public static void Add<TOuterKey, TDictionary, TInnerKey, TValue>(
            this IDictionary<TOuterKey, TDictionary> data, TOuterKey outerKey, TInnerKey innerKey, TValue value)
            where TDictionary : class, IDictionary<TInnerKey, TValue>, new()
        {
            TDictionary innerData;
            if (!data.TryGetValue(outerKey, out innerData))
            {
                innerData = new TDictionary();
                data.Add(outerKey, innerData);
            }
            innerData.Add(innerKey, value);
        }

    }
}
